﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MatthiWare.PortChecker
{
    public class PortCollection
        : List<Port>
    {
        public PortCollection()
            : base()
        {
            Load();
        }

        public Port GetPortInfo(UInt16 port)
        {
            foreach (Port pInfo in this.ToArray())
            {
                if (pInfo.PortNumber == port)
                    return pInfo;
            }

            return new Port(port, "unknown", "Unassigned");
        }

        private void Load()
        {
            Port p;

            p = new Port(0, "Reserved", "Reserved");
            this.Add(p);

            p = new Port(1, "tcpmux", "TCP Port Service Multiplexer");
            this.Add(p);

            p = new Port(2, "compressnet", "Management Utility");
            this.Add(p);

            p = new Port(3, "compressnet", "Reserved");
            this.Add(p);

            p = new Port(5, "RJE", "Remote Job Entry");
            this.Add(p);

            p = new Port(7, "Echo", "Echo");
            this.Add(p);

            p = new Port(20, "FTP Data", "File Transfer [Default Data]");
            this.Add(p);

            p = new Port(21, "FTP", "File Transfer [Control]");
            this.Add(p);

            p = new Port(22, "SSH", "The Secure Shell (SSH) Protocol");
            this.Add(p);

            p = new Port(23, "Telnet", "Telnet");
            this.Add(p);

            p = new Port(25, "SMTP", "Simple Mail Transfer Protocol");
            this.Add(p);

            p = new Port(39, "RLP", "Resource Location Protocol");
            this.Add(p);

            p = new Port(43, "Nicname", "Who Is");
            this.Add(p);

            p = new Port(49, "Tacas", "Login Host Protocol (TACACS)");
            this.Add(p);

            p = new Port(53, "Domain", "Domain Name Server");
            this.Add(p);

            p = new Port(63, "Whois++", "WhoIs++ extended whois service");
            this.Add(p);

            p = new Port(68, "DHCP/Bootpc", "Dynamic Host Configuration Protocol/Bootstrap Protocol Client");
            this.Add(p);

            p = new Port(69, "TFTP", "Trivial File Transfering Protocol uses UDP and provides no security features");
            this.Add(p);

            p = new Port(80, "HTTP", "World Wide Web HyperText Transfer Protocol");
            this.Add(p);

            p = new Port(107, "rtelnet", "Remote Telnet");
            this.Add(p);

            p = new Port(109, "POP2", "Post Office Protocol v2");
            this.Add(p);

            p = new Port(110, "POP3", "Post Office Protocol v3");
            this.Add(p);

            p = new Port(115, "SFTP", "Secure File Transfer Protocol");
            this.Add(p);

            p = new Port(118, "SQLServ", "SQL Services");
            this.Add(p);

            p = new Port(119, "NNTP", "Network New Transfer Protocol");
            this.Add(p);

            p = new Port(123, "NTP", "Network Time Protocol");
            this.Add(p);

            p = new Port(137, "NetBIOS-ns", "Network Basic Input Output System Name Service an application programming interface (API) for a DOS BIOS with extended LAN functions");
            this.Add(p);

            p = new Port(138, "NetBIOS-dgm", "Network Basic Input Output System Datagram Service");
            this.Add(p);

            p = new Port(139, "NetBIOS-ssn", "Network Basic Input Output System Session Service");
            this.Add(p);

            p = new Port(143, "IMAP", "Internet Message Access Protocol");
            this.Add(p);

            p = new Port(161, "SNMP", "Simple Network Management Protocol");
            this.Add(p);

            p = new Port(179, "BGP", "Border Gateway Protocol, an exterior gateway routing protocol that enables groups of routers to share routing information. See RFC 1771");
            this.Add(p);

            p = new Port(190, "GACP", "Gateway Acces Protocol");
            this.Add(p);

            p = new Port(194, "IRC", "Internet Relay Chat");
            this.Add(p);

            p = new Port(220, "IMAP3", "Internet Message Access Protocol v3");
            this.Add(p);

            p = new Port(389, "LDAP", "Lightweight Directory Access Protocol");
            this.Add(p);

            p = new Port(443, "SSL/HTTPS", "Secure Socket Layer / HTTP over TLS/SSL");
            this.Add(p);

            p = new Port(445, "SMB", "NetBIOS over TCP");
            this.Add(p);

            p = new Port(993, "SIMAP", "Secure Internet Message Access Protocol");
            this.Add(p);

            p = new Port(995, "SPOP", "Secure Post Office Protocol");
            this.Add(p);

            p = new Port(1080, "Socks", "Sockets used for socks-proxyserver, layer 5 of OSI-model (session layer)");
            this.Add(p);

            p = new Port(8080, "HTTP-Alt", "HTTP-Alternative see HTTP (80)");
            this.Add(p);
        }
    }
}
